package top.zywork.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import top.zywork.constant.CommonConstant;
import top.zywork.dos.SchoolPlaceCbtDO;
import top.zywork.dos.SchoolPlaceDO;
import top.zywork.dto.PagerDTO;
import top.zywork.mapper.SchoolPlaceMapper;
import top.zywork.query.SchoolPlaceCbtQuery;
import top.zywork.query.SchoolPlaceQuery;
import top.zywork.service.SchoolPlaceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author
 * @since 2020-10-13
 */
@Service
public class SchoolPlaceServiceImpl extends ServiceImpl<SchoolPlaceMapper, SchoolPlaceDO> implements SchoolPlaceService {


    @Override
    public SchoolPlaceDO checkPlace(Long schoolId, Long id) {
        return baseMapper.selectOne(new QueryWrapper<SchoolPlaceDO>()
                .eq("is_active", CommonConstant.IS_ACTIVE_TRUE)
        .eq("school_id",schoolId)
        .eq("id",id));
    }

    @Override
    public PagerDTO listById(Long id) {
        List<Object> schoolPlaceCbtDOS = baseMapper.listById(id);
        return PagerDTO.builder().total(Long.valueOf(schoolPlaceCbtDOS.size())).rows(schoolPlaceCbtDOS).build();
    }

    @Override
    public PagerDTO listAllByCondition(SchoolPlaceQuery schoolPlaceQuery) {
        List<Object> objects = baseMapper.listAllByCondition(schoolPlaceQuery);
        Long aLong = baseMapper.countByCondition(schoolPlaceQuery);
        return PagerDTO.builder().rows(objects).total(aLong).build();
    }

    @Override
    public PagerDTO listPageByCondition(SchoolPlaceQuery schoolPlaceQuery) {
        List<Object> objects = baseMapper.listPageByCondition(schoolPlaceQuery);
        Long aLong = baseMapper.countByCondition(schoolPlaceQuery);
        return PagerDTO.builder().rows(objects).total(aLong).build();
    }
}
